package com.aaa.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName(value = "user")
public class User implements UserDetails {
    @TableId(value = "uid")
   private int uid;
     private String       uname;
   private String username;
     private String       password;
   private String sex;
          private String  address;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
   private Date createtime;
     private String       phone;
  private String  email;
       private int     rid;
  private String  picture;
   private String     state;
   @TableField(exist = false)
private Collection authorties;


    /*
     * 获取用户权限
     * */

    public void setAuthorities(Collection authorities) {

        this.authorties=authorities;
    }
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
//        StringBuffer str=new StringBuffer();
//        if(this.eusername.equals("zs")){
//            str.append("ROLE_ADMIN,ADMIN,add,update,delete,select");
//        }else {
//            str.append("ROLE_USER,ROLE_TEST,TEST,select");
//        }
//        return AuthorityUtils.commaSeparatedStringToAuthorityList(str.toString());
        return this.authorties;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.username;
    }
    //用户是否过期 1过期
    @Override
    public boolean isAccountNonExpired() {
        return true;

    }
    //用户是否被锁定 2锁定
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }
    //凭证是否过期：密码
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }
    //是否启用
    @Override
    public boolean isEnabled() {
        return true;
    }

}
